package com.bawei.lib_storage.mmkv

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken

object Gson {
    val gson: Gson by lazy {
        GsonBuilder().serializeNulls().disableHtmlEscaping().create()
    }

    fun toJson(obj:Any?):String{
        return gson.toJson(obj)
    }

    inline fun <reified T> fromJson(json: String): T? {
        return gson.fromJson(json, object : TypeToken<T>() {}.type)
    }

    fun <T> formJson(json: String, clazz: Class<T>): T {
        return gson.fromJson(json, clazz)
    }
}